<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2019/1/9
 * Time: 9:07
 */

namespace app\sports_admin\model;


use think\Model;
use think\Request;
use traits\model\SoftDelete;

class Banner extends Model
{
    use SoftDelete;
    protected $table = "banner";
    protected $pk    = "id";
    protected $autoWriteTimestamp = true;

    public function getUrlAttr($value)
    {
        return substr($value,0,30).'...';
    }
    /**
     * 导航图列表
     */
    public static function bannerList($page,$rows,$sort,$sortOrder)
    {
        $adminList = self::page($page)
            ->limit($rows)
            ->order("{$sort}","{$sortOrder}")->select();

        $adminCount = self::count();
        return ['rows'=>$adminList,'total'=>$adminCount];
    }
    /**
     * 删除导航图
     */
    public static function bannerDel()
    {
        $id = Request::instance()->only('id');
        return self::destroy($id['id']);
    }
    /**
     * 添加导航图
     */
    public static function bannerAdd()
    {
        $data = Request::instance()->only('img,url');
        return self::create(['url'=>$data['url'],'photo'=>$data['img']]);
    }

}